﻿Public Class WorkOrderHistoryWrapper
#Region "Properties"

    Public _action As String
    Public Property Action As String
        Get
            Return _action
        End Get
        Set(ByVal value As String)
            _action = value
        End Set
    End Property

    Public _actionDate As String
    Public Property ActionDate As String
        Get
            Return _actionDate
        End Get
        Set(ByVal value As String)
            _actionDate = value
        End Set
    End Property

    Public _byUser As String
    Public Property ByUser As String
        Get
            Return _byUser
        End Get
        Set(ByVal value As String)
            _byUser = value
        End Set
    End Property

#End Region

    Public Shared Function GetHistoryListFrom(ByVal wo As Equipment.DataAccess.WorkOrder) As List(Of WorkOrderHistoryWrapper)
        Dim wrapperList As New List(Of WorkOrderHistoryWrapper)

        Dim item As New WorkOrderHistoryWrapper
        item.Action = "Created"
        item.ActionDate = wo.DateCreated.ToString("dd-MMM-yyyy hh:mm")
        item.ByUser = If(wo.CreatedByUser IsNot Nothing, wo.CreatedByUser.FullName, "Automatic Service")
        wrapperList.Add(item)

        If (wo.PerformedByUser IsNot Nothing) Then
            item = New WorkOrderHistoryWrapper
            item.Action = If(wo.HasException, "Performed with exception", "Performed")
            item.ActionDate = wo.PerformedDate.Value.ToString("dd-MMM-yyyy hh:mm")
            item.ByUser = wo.PerformedByUser.FullName
            wrapperList.Add(item)
        End If

        If (wo.ApprovedByUser IsNot Nothing) Then
            item = New WorkOrderHistoryWrapper
            item.Action = "Approved"
            item.ActionDate = wo.ApprovedDate.Value.ToString("dd-MMM-yyyy hh:mm")
            item.ByUser = wo.ApprovedByUser.FullName
            wrapperList.Add(item)
        End If

        Return wrapperList
    End Function
End Class
